home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-06-18 | 3.8 KB | 131 lines | [TEXT/dosa] |
- // DesktopMenu.java : this is a Java source code file for the program Facade.
- // Copyright 1998, Andrew S. Downs
- // andrew.downs@tulane.edu
- //
- // This source code is distributed as freeware.
- // Just keep this author information in the file. Enjoy!
-
- import java.awt.*;
- import java.io.*;
- import java.util.*;
-
- public class DesktopMenu extends DesktopComponent implements Serializable {
- boolean enabled = false;
- Color activeItemColor, inactiveItemColor;
- Color highlightBackgroundColor, highlightForegroundColor;
- DesktopMenuItem activeItem;
- Rectangle itemBounds;
- Vector vector;
-
- DesktopMenu() {
- super();
- this.vector = new Vector();
- this.itemBounds = new Rectangle();
- }
-
- public int getWidestItem( FontMetrics theFontMetrics ) {
- // Determine widest menu item.
- int tempWidth = 0;
- Vector v = this.getVector();
-
- for ( int j = 0; j < v.size(); j++ ) {
- int temp = theFontMetrics.stringWidth( ( ( DesktopMenuItem )v.elementAt( j ) ).getLabel() );
- if ( temp > tempWidth )
- tempWidth = temp;
- }
-
- return tempWidth;
- }
-
- public void setItemLocations( FontMetrics theFontMetrics ) {
- int tempWidth = this.getWidestItem( theFontMetrics );
-
- int newX = this.getX();
- int newY = Global.defaultMenuBarHeight + theFontMetrics.getHeight();
- int newWidth = tempWidth + ( 2 * Global.defaultMenuHSep );
- int newHeight = theFontMetrics.getHeight() + Global.defaultMenuItemVSep;
-
- Vector v = this.getVector();
-
- for ( int j = 0; j < v.size(); j++ ) {
- if ( ( ( DesktopMenuItem )v.elementAt( j ) ).getLabel().equals( Global.menuSep ) ) {
- ( ( DesktopMenuItem )v.elementAt( j ) ).setDrawPoint( newX, newY );
- ( ( DesktopMenuItem )v.elementAt( j ) ).setBounds( newX, newY - theFontMetrics.getHeight() + Global.defaultMenuItemVSep, newWidth, 3 * Global.defaultMenuItemVSep );
- newY += 4 * Global.defaultMenuItemVSep;
- continue;
- }
-
- ( ( DesktopMenuItem )v.elementAt( j ) ).setDrawPoint( newX, newY );
- ( ( DesktopMenuItem )v.elementAt( j ) ).setBounds( newX, newY - theFontMetrics.getHeight(), newWidth, newHeight + Global.defaultMenuItemVSep );
- newY += theFontMetrics.getHeight() + Global.defaultMenuItemVSep;
- }
-
-
- this.itemBounds.setBounds( this.getBounds().x - Global.defaultMenuHSep, Global.defaultMenuBarHeight, tempWidth + ( 2 * Global.defaultMenuHSep ), ( ( ( DesktopMenuItem )v.elementAt( v.size() - 1 ) ).getBounds().y ) + ( ( ( DesktopMenuItem )v.elementAt( v.size() - 1 ) ).getBounds().height ) - Global.defaultMenuBarHeight + ( Global.defaultMenuItemVSep ) );
- }
-
- public void setVector( Vector v ) {
- this.vector = v;
- }
-
- public Vector getVector() {
- return this.vector;
- }
-
- public void setEnabled( boolean b ) {
- this.enabled = b;
- }
-
- public boolean getEnabled() {
- return this.enabled;
- }
-
- public void setActiveItemColor( Color c ) {
- this.activeItemColor = c;
- }
-
- public Color getActiveItemColor() {
- return this.activeItemColor;
- }
-
- public void setInactiveItemColor( Color c ) {
- this.inactiveItemColor = c;
- }
-
- public Color getInactiveItemColor() {
- return this.inactiveItemColor;
- }
-
- public void setHighlightBackgroundColor( Color c ) {
- this.highlightBackgroundColor = c;
- }
-
- public Color getHighlightBackgroundColor() {
- return this.highlightBackgroundColor;
- }
-
- public void setHighlightForegroundColor( Color c ) {
- this.highlightForegroundColor = c;
- }
-
- public Color getHighlightForegroundColor() {
- return this.highlightForegroundColor;
- }
-
- public void setActiveItem( DesktopMenuItem d ) {
- this.activeItem = d;
- }
-
- public DesktopMenuItem getActiveItem() {
- return this.activeItem;
- }
-
- public void setItemBounds( Rectangle r ) {
- this.itemBounds = r;
- }
-
- public Rectangle getItemBounds() {
- return this.itemBounds;
- }
- }
-